package main

import (
	"fmt"
	"go.uber.org/zap"
	"laxkits/lib/laxoffice"
	"laxkits/lib/laxutils"
	"laxkits/lib/zlogger"
)

type XmlNode struct {
	Log zlogger.LaxLogNode `xml:"log"`
}

var globalXmlConfig XmlNode

func main() {
	if err := laxutils.LoadXmlFile("../eg.xml", &globalXmlConfig); err != nil {
		fmt.Println(err)
		return
	}
	zlogger.InitLogger(&globalXmlConfig.Log)
	if err := laxoffice.CSVEachRow("C:/Users/fissuretang/Desktop/aaa.csv", 2,
		func(csvIndex int, csvRow []string) error {
			if csvIndex < 5 {
				zap.S().Info(csvIndex, csvRow[0], csvRow[2], csvRow[10])
			}
			return nil
		}); err != nil {
		zap.S().Warn(err)
	}
	rows, err := laxoffice.LoadCSVAll("C:/Users/fissuretang12/Desktop/aaa.csv", 2)
	if err != nil {
		zap.S().Warn(err)
	} else {
		//zap.S().Info(rows)
		zap.S().Infof("%d, %d", len(rows), len(rows[0]))
	}
	w, err := laxoffice.NewLaxCSVWriter("./csv/a.csv")
	if err != nil {
		zap.S().Warn("打开csvwriter失败,", err)
		return
	}
	s := []string{"1","2","444"}
	w.Write(s)
	s[2] = "13123"
	w.Write(s)
	s1 := [][]string{
		{"a", "b"},
		{"a", "b", "c", "d"},
	}
	w.WriteAll(s1)
	w.WaitFinish()
	//laxutils.CloseGracefully(nil)
}
